﻿class Program
{
    static void Main(string[] args)
    {
        #region 对非数字类型去重正确
        List<Student> list2 = new List<Student>
        {
            new Student{name="张三",age=20, gender="男"},
            new Student{name="张三",age=20,gender="男"},
            new Student{name="李四",age=20,gender="男"},
            new Student{name="李四",age=20,gender="男"},
            new Student{name="王五",age=20,gender="女"},
            new Student{name="赵六",age=20,gender="女"},
            new Student{name="陈启",age=20,gender="女"},
            new Student{name="陈启",age=20,gender="女"},
        };
        foreach (var item in list2)
        {
            Console.Write(item.name + " ");
        }
        var res2 = list2.Distinct(new userCompare());
        Console.WriteLine();
        Console.WriteLine("********************************");
        foreach (var item in res2)
        {
            Console.Write(item.name + " ");
        }
        //声明一个类 实现IEqualityComparer接口
        //实现方法bool Equals(T x, T y);
        //int GetHashCode(T obj);
        //然后再内部写上比较的字段和属性 比较才能成功 才能去重
        #endregion
        Console.ReadLine();
    }
}


public class Student
{
    public int age { get; set; }
    public string name { get; set; }
    public string gender { get; set; }
}


public class userCompare : IEqualityComparer<Student>
{

    #region IEqualityComparer<user> Members

    public bool Equals(Student x, Student y)
    {

        return x.name.Equals(y.name);

    }

    public int GetHashCode(Student obj)
    {

        return obj.name.GetHashCode();

    }

    #endregion

}